package com.yqg.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.yqg.manage.entity.Params;
import com.yqg.manage.mapper.ParamsMapper;
import com.yqg.manage.service.IParamsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ParamsServiceImpl 服务实现类
 *
 * @author suzhuang
 * @since 2023-07-05
 */
@Service
public class ParamsServiceImpl extends MPJBaseServiceImpl<ParamsMapper, Params> implements IParamsService {

    @Autowired
    ParamsMapper paramsMapper;

    @Override
    public List<Params> findLastNodeParams(Integer nodeId, String caseNo) {
        return paramsMapper.findLastNodeParams(nodeId, caseNo);
    }

    @Override
    public List<Map<String, Object>> getPdfList(String caseId) {
        List<Map<String, Object>> pdfList = paramsMapper.getPdfList(caseId);
        return pdfList;
    }

    @Override
    public void updateStatusByCaseId(Long caseId,String toStatus,List<String> fromStatus) {
        LambdaUpdateWrapper<Params> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(Params::getStatus, toStatus)
                .eq(Params::getCaseId, caseId)
                .in(Params::getStatus, fromStatus);
        this.update(updateWrapper);
    }

    @Override
    public Boolean getUnfinished(Long caseId,List<String> status) {
        LambdaQueryWrapper<Params> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Params::getCaseId,caseId)
                .in(Params::getStatus,status);
        List<Params> list = this.list(queryWrapper);
        return !list.isEmpty();
    }
}
